<?php
/**
 * @file
 */
/**
 * Renders the message input form.
 *
 * @return string
 *   The HTML for the input form.
 */
function ajaxchatbox_message_form($form, &$form_state = array()) {
  global $base_path;
  $form = array();

  $form['ajaxchatbox_style']['#tree'] = TRUE;

  $form['ajaxchatbox_style']['font_weight'] = array(
    '#type' => 'checkbox',
    '#title' => t('B'),
    '#default_value' => 'bold'
  );
  $form['ajaxchatbox_style']['font_style'] = array(
    '#type' => 'checkbox',
    '#title' => t('I'),
    '#default_value' => 'italic'
  );
  $form['ajaxchatbox_style']['text_decoration'] = array(
    '#type' => 'checkbox',
    '#title' => t('U'),
    '#default_value' => 'underline'
  );

  $font_options = array(
     '' => t('Choose Font'), 'Arial' => t('Arial'), 'Arial Black' => t('Arial Black'), 'Book Antiqua' => t('Book Antiqua'), 'Century Gothic' => t('Century Gothic'), 'Comic Sans MS' => t('Comic Sans MS'), 'Courier New' => t('Courier New'), 'Impact' => t('Impact'), 'Tahoma' => t('Tahoma'), 'Times New Roman' => t('Times New Roman'), 'Trebuchet MS' => t('Trebuchet MS'), 'Verdana' => t('Verdana')
  );
  $color_options = array(
     '' => t('Choose Color'), 'Gold' => t('Gold'), 'Khaki' => t('Khaki'), 'Orange' => t('Orange'), 'LightPink' => t('LightPink'), 'Salmon' => t('Salmon'), 'DarkGreen' => t('DarkGreen'), 'DarkCyan' => t('DarkCyan'), 'LightSeaGreen' => t('LightSeaGreen'), 'LawnGreen' => t('LawnGreen'), 'MediumSeaGreen' => t('MediumSeaGreen'), 'BlueViolet' => t('BlueViolet'), 'Cyan' => t('Cyan'), 'Blue' => t('Blue'), 'DodgerBlue' => t('DodgerBlue'), 'LightSkyBlue' => t('LightSkyBlue'), 'White' => t('White'), 'DimGray' => t('DimGray'), 'DarkGray' => t('DarkGray'), 'Black' => t('Black')
  );

  $form['ajaxchatbox_style']['font_family'] = array(
    '#type' => 'select',
    '#title' => t('Font'),
    '#default_value' => 0,
    '#options' => $font_options
  );

  $form['ajaxchatbox_style']['color'] = array(
    '#type' => 'select',
    '#title' => t('Color'),
    '#default_value' => 0,
    '#options' => $color_options
  );

  $smileys = db_query('SELECT * FROM {smiley} WHERE status = 1')->fetchAll();
  $path = $base_path . variable_get('smiley_path', drupal_get_path('module', 'smiley') . '/packs');

  $form['smilies'] = array(
    '#type' => 'fieldset',
    '#title' => t('Smiles'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE
  );

  $form['smilies']['smileys'] = array(
    '#type' => 'markup',
    '#markup' => theme('ajaxchatbox_smileys', array('smileys' => $smileys, 'path' => $path))
  );

  $form['ajaxchatbox_message'] = array(
    '#type' => 'textfield',
    '#maxlength' => 100,
  );

  $form['send'] = array(
    '#type' => 'submit',
    '#value' => t('Send'),
  );

  $form['#theme'] = array('ajaxchatbox_message_form');

  return $form;
}

/**
 * Submit callback for the message input form.
 *
 * Will only be used for non-JS clients, while Ajax processing
 * uses chatblock_chat_update_callback and its internal logic.
 *
 * @see chatblock_chat_update_callback()
 */
function ajaxchatbox_message_form_submit($form, &$form_state) {
  if (isset($form_state['values']['ajaxchatbox_message'])) {
    $message = $form_state['values']['ajaxchatbox_message'];
    ajaxchatbox_save_message(array('message' => $message));
  }
  return;
}

